<?php
class Master_kelas extends CI_Model 
{

	function __construct()
	{
		parent::__construct();
	}
	
	function add($dataInsert)
	{
		$query = $this->db->insert('mr_kelas', $dataInsert);
		return $query;
	}
	
	function read()
	{	
		$this->db->order_by('kelas');		
		$query=$this->db->get('mr_kelas');
		return $query->result();
	}
	
	function edit($id_mr_kelas)
	{
		$this->db->where('id_mr_kelas',$id_mr_kelas);
		$query=$this->db->get('mr_kelas');
		return $query->result();
	}
	
	function update($id_mr_kelas,$dataUpdate)
	{
		$this->db->where('id_mr_kelas', $id_mr_kelas);
		$update = $this->db->update('mr_kelas', $dataUpdate);
		return $update;
	}
	
	function delete($id_mr_kelas)
	{
		$this->db->where('id_mr_kelas', $id_mr_kelas);
		$delete = $this->db->delete('mr_kelas');
		return $delete;
	}

	function limit($limit,$offset)
	{	
		$this->db->order_by('kelas');		
		$query=$this->db->get('mr_kelas',$limit,$offset);
		return $query->result();
	}

	function num_rows()
	{	
		$query = $this->db->get('mr_kelas');
		return $query->num_rows();
	}
	
	function get_detail($id){
		$sql="select * from mr_kelas where id_mr_kelas ='".$id."'";
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->row_array();
		}else{
			return array();
		}
	}
	
	function get_kelas_lembaga($id_lembaga,$id_tapel){
		$sql="select * from mr_kelas where id_mr_kelas in (select id_mr_kelas from atur_kelas 
				where id_mr_th_ajaran='".$id_tapel."' and id_lembaga='".$id_lembaga."')";
		$query=$this->db->query($sql);
		if ($query->num_rows()>0){
			return $query->result_array();
		}else{
			return array();
		}
	}

}